package com.fivec.javaproject;


import com.fivec.javaproject.bean.*;
import com.fivec.javaproject.btcrpcentity.ChainInfo;
import com.fivec.javaproject.btcrpcentity.MemPoolInfo;
import com.fivec.javaproject.btcrpcentity.RpcDeserialization;
import com.fivec.javaproject.btcrpcentity.TxOutSetInfo;
import com.fivec.javaproject.rpc.*;
import com.fivec.javaproject.service.*;

import java.math.BigDecimal;
import java.security.KeyPair;
import java.util.List;
import java.util.Random;
import java.util.Scanner;

/**
 * @author wangyizhu
 * @version "1.8.0_131"
 * @email 2641956765@qq.com
 * @desc:
 * @Time 2021/12/14 18:26
 */
public class test {
    public static boolean start() {
        while (true) {
            System.out.println("⚜⚜⚜⚜⚜⚜⚜比特币客户端功能⚜⚜⚜⚜⚜⚜⚜");
            System.out.println("a:获取当前链头区块哈希");
            System.out.println("b:获取指定高度的区块哈希值");
            System.out.println("c:获取指定哈希区块");
            System.out.println("d:获取区块链当前状态");
            System.out.println("e:获取出块难度");
            System.out.println("f:获取当前区块高度");
            System.out.println("g:获取交易池信息");
            System.out.println("h:获取交易输出(UTxo)集信息");
            System.out.println("t:退出");
            System.out.print("请输入:");
            Scanner scanner = new Scanner(System.in);
            String chang = scanner.next();
            Random ra = new Random();
            int id = ra.nextInt(100) + 1;
            switch (chang) {
                case "a":
                    GetBestBlockHash getBestBlockHash = new GetBestBlockHash();
                    RpcDeserialization bestBlock = getBestBlockHash.getBestBlockHash(id);
                    System.out.println();
                    System.out.println("当前链头区块哈希:" + bestBlock.getResult());
                    System.out.println();
                    return true;
                case "b":
                    GetBlockHash getBlockHash = new GetBlockHash();
                    System.out.print("输入区块高度:");
                    int height = scanner.nextInt();
                    String hash = getBlockHash.getBlockHash(id, height).getResult();
                    System.out.println("高度为" + height + "的哈希值为:" + hash);
                    System.out.println();
                    return true;
                case "c":
                    System.out.println("输入区块哈希:");
                    String hashValue = scanner.next();
                    GetBlock getBlock = new GetBlock();
                    System.out.println("获取指定哈希区块:  " + getBlock.getBlock(id, hashValue).getResult());
                    return true;
                case "d":
                    GetBlockChainInfo info = new GetBlockChainInfo();
                    System.out.println();
                    ChainInfo result = info.getBlockChainInfo(id);
                    System.out.println("区块链名称: " + result.getChain());
                    System.out.println("本地最优链中的已验证区块数量: " + result.getBlocks());
                    System.out.println("本地最优区块头链表中的已验证区块头数量: " + result.getHeaders());
                    System.out.println("本地最优链中最高区块的哈希: " + result.getBestblockhash());
                    System.out.println("区块难度: " + result.getDifficulty());
                    System.out.println("最近区块之前的11个区块的中位时间: " + result.getMediantime());
                    double num = result.getVerificationprogress();
                    BigDecimal bigDecimal = new BigDecimal(num);
                    String a = bigDecimal.toString();
                    System.out.println("区块验证进度: " + a);
                    System.out.println("区块链上工作量总值: " + result.getChainwork());
                    System.out.println("删除目标大小:" + result.getPrune_target_size());
                    System.out.println("占用磁盘大小:" + result.getSize_on_disk() + "KB");
                    System.out.println();
                    return true;
                case "e":
                    GetDifficulty difficulty = new GetDifficulty();
                    System.out.println();
                    System.out.println("出块难度:" + difficulty.getDifficulty(id).getResult());
                    System.out.println();
                    return true;
                case "f":
                    GetBlockCount count = new GetBlockCount();
                    System.out.println();
                    System.out.println("当前区块高度:" + count.getBlockCount(id).getResult());
                    System.out.println();
                    return true;
                case "g":
                    GetMemPoolInfo getMemPoolInfo = new GetMemPoolInfo();
                    MemPoolInfo mem = getMemPoolInfo.getMenPoolInfo(id);
                    System.out.println();
                    System.out.println("池内交易数量:" + mem.getSize());
                    System.out.println("池内交易占用字节数:" + mem.getBytes());
                    System.out.println("交易池占用的内存空间字节数:" + mem.getUsage());
                    System.out.println("交易池最大可用内存:" + mem.getMaxmempool());
                    BigDecimal bigDecimal1 = new BigDecimal(mem.getMempoolminfee());
                    String a1 = bigDecimal1.toString();
                    System.out.println("交易池最低交易费率:" + a1);
                    System.out.println();
                    return true;
                case "h":
                    GetTxOutSetInfo getTxOutSetInfo = new GetTxOutSetInfo();
                    TxOutSetInfo tx = getTxOutSetInfo.getTxOutSetInfo(id);
                    System.out.println();
                    System.out.println("本地最优链的高度:" + tx.getHeight());
                    System.out.println("最高位置区块的哈希:" + tx.getBestblock());
                    System.out.println("包含utxo的交易数量:" + tx.getTransactions());
                    System.out.println("UTXO总数:" + tx.getTxouts());
                    System.out.println("序列化后的UTXO集合的总字节数:" + tx.getDisk_size());
                    System.out.println("无意义UTXO大小的度量:" + tx.getBogosize());
                    System.out.println("序列化后的TUXO集合的SHA256哈希值:" + tx.getHash_serialized_2());
                    System.out.println("UTXO集合中的比特币总数:" + tx.getTotal_amount());
                    System.out.println();
                    return true;
                case "t":
                    run();
                default:
                    System.out.println("输入错误，请重试！");
            }
        }
    }

    public static void run() {
        while (true) {
            System.out.println();
            System.out.println("🔱🔱🔱🔱🔱🔱🔱🔱🔱🔱🔱🔱🔱🔱🔱🔱");
            System.out.println("1:热门视频");
            System.out.println("2:手机号码归属地");
            System.out.println("3:天气预报");
            System.out.println("4:新闻头条");
            System.out.println("5:星座运势");
            System.out.println("6:老黄历");
            System.out.println("7:生成比特币地址");
            System.out.println("8:调用比特币客户端功能");
            System.out.println("0:退出");
            System.out.println("🚸🚸🚸🚸🚸🚸🚸🚸🚸🚸🚸🚸🚸🚸🚸🚸🚸🚸");
            System.out.print("请输入:");
            Scanner scanner = new Scanner(System.in);
            String choose = scanner.next();
            switch (choose) {
                case "1":
                    List<HotVideo> result;
                    HotVideService hotVideService = new HotVideService();
                    result = hotVideService.getHotVideo();
                    int count = 0;
                    for (HotVideo v : result
                    ) {
                        count++;
                        System.out.println("第" + count + "条热门数据");
                        System.out.println("视频标题: " + v.title);
                        System.out.println("视频发布者昵称: " + v.author);
                        System.out.println("视频播放页面URL: " + v.share_url);
                        System.out.println("视频封面图: " + v.item_cover);
                        System.out.println("热度指数: " + v.hot_value);
                        System.out.println("视频热词: " + v.hot_words);
                        System.out.println("播放数: " + v.play_count);
                        System.out.println("点赞数: " + v.digg_count);
                        System.out.println("评论数: " + v.comment_count);
                        System.out.println();
                    }
                    break;
                case "2":
                    System.out.println("请输入手机号");
                    String phoneNumber = scanner.next();
                    Address result2;
                    AddressService addressService = new AddressService();
                    result2 = addressService.getAddressMessage(phoneNumber);
                    if (result2 != null) {
                        System.out.println("省份:" + result2.province);
                        System.out.println("城市:" + result2.city);
                        System.out.println("区号:" + result2.areaCode);
                        System.out.println("邮编，:" + result2.zip);
                        System.out.println("运营商:" + result2.company);
                        System.out.println();
                    } else {
                        System.out.println(phoneNumber + "， 不是完整的11位手机号或者正确的手机号前七位!");
                    }
                    break;
                case "3":
                    System.out.println("请输入要查询的城市 例如：南昌，北京...");
                    String city = scanner.next();
                    Weather resultWeather;
                    WeatherService weatherService = new WeatherService();
                    resultWeather = weatherService.getWeatherMessage(city);
                    if (resultWeather != null) {
                        System.out.println("查询城市:" + resultWeather.getCity());
                        System.out.println("               当前天气详情情况");
                        System.out.print("天气:" + resultWeather.getRealtime().getInfo() + "  温度:" + resultWeather.getRealtime().getTemperature() + "  湿度:" + resultWeather.getRealtime().getHumidity() + "  风向:" + resultWeather.getRealtime().getDirect() + "  风力:" + resultWeather.getRealtime().getPower() + "  空气质量指数:" + resultWeather.getRealtime().getAqi());
                        System.out.println();
                        System.out.println("               近5天天气情况");
                        List<Future> resultWeatherFuture = resultWeather.getFuture();
                        for (Future f : resultWeatherFuture
                        ) {
                            System.out.print("日期:" + f.getDate() + "  " + "最低温/最高温:" + f.getTemperature() + "  " + "天气:" + f.getWeather() + "  " + "风向:" + f.getDirect() + "  ");
                            System.out.println();
                        }
                    } else {
                        System.out.println("输入城市错误！！！");
                    }
                    break;
                case "4":
                    int a = 0;
                    System.out.println("请输入新闻类型  例如：" + "top(推荐,默认)" + "  guonei(国内)" + "  guoji(国际)" + "  yule(娱乐)" + "  tiyu(体育)" + "  junshi(军事)" + "  jiankang(健康) ...");
                    String type = scanner.next();
                    HeadlineService headlineService = new HeadlineService();
                    List<HeadlineData> data = headlineService.getHeadlineMessage(type);
                    if (data != null) {
                        for (HeadlineData d : data
                        ) {
                            a++;
                            System.out.println("第" + a + "条新闻数据");
                            System.out.println("新闻ID:" + d.getUniquekey());
                            System.out.println("新闻标题:" + d.getTitle());
                            System.out.println("时间:" + d.getDate());
                            System.out.println("分类:" + d.getCategory());
                            System.out.println("来源:" + d.getAuthor_name());
                            System.out.println("访问链接:" + d.getUrl());
                            System.out.println("图片链接:" + d.getThumbnail_pic_s());
                            System.out.println("图片链接:" + d.getThumbnail_pic_s02());
                            System.out.println("图片链接:" + d.getThumbnail_pic_s03());
                            System.out.println();
                        }
                    } else {
                        System.out.println("输入类型错误");
                    }
                    break;
                case "5":
                    System.out.println("请输入星座，如:双鱼座");
                    String constellation = scanner.next();
                    System.out.println("请输入运势类型：today,tomorrow,week,month,year");
                    String mold = scanner.next();
                    HoroscopeRun(constellation, mold);
                    break;
                case "6":
                    HuangLiService huangLiService = new HuangLiService();
                    System.out.println("请输入日期， 格式2014-09-09");
                    String day = scanner.next();
                    HuangLi data1 = huangLiService.getCalendarMessage(day);
                    System.out.println("阳历: " + data1.getYangli());
                    System.out.println("阴历: " + data1.getYinli());
                    System.out.println("五行: " + data1.getWuxing());
                    System.out.println("冲煞: " + data1.getChongsha());
                    System.out.println("彭祖百忌: " + data1.getBaiji());
                    System.out.println("吉神宜趋: " + data1.getJishen());
                    System.out.println("宜: " + data1.getYi());
                    System.out.println("凶神宜忌: " + data1.getXiongshen());
                    System.out.println("忌: " + data1.getJi());
                    break;
                case "7":
                    com.fivec.javaproject.address.Address address = new com.fivec.javaproject.address.Address();
                    KeyPair keyPair = address.generateKeys();
                    String add = address.newAddress(keyPair);
                    System.out.println();
                    System.out.println("生成的比特币地址为:" + add);
                    System.out.println("这个地址为:" + address.Isvalidforadress(add));
                    break;
                case "8":
                    while (true) {
                        boolean s = start();
                    }
                case "0":
                    System.out.println("欢迎使用");
                    System.exit(0);
                default:
                    System.out.println("输入错误，请重试！");
            }

        }
    }

    public static void HoroscopeRun(String constellation, String type) {
        HoroscopeService horoscopeService = new HoroscopeService();
        HoroscopeCommon horoscopeCommon = horoscopeService.getHoroscopeMessage(constellation, type);
        if (horoscopeCommon.getError_code() != 205802) {
            switch (type) {
                case "today":
                    Today today = horoscopeCommon.getToday();
                    System.out.println("日期:" + today.getDatetime());
                    System.out.println("星座名称:" + today.getName());
                    System.out.println("速配星座:" + today.getQFriend());
                    System.out.println("幸运色:" + today.getColor());
                    System.out.println("健康指数:" + today.getHealth());
                    System.out.println("爱情指数:" + today.getLove());
                    System.out.println("财运指数:" + today.getMoney());
                    System.out.println("幸运数字:" + today.getNumber());
                    System.out.println("财运指数:" + today.getMoney());
                    System.out.println("工作指数:" + today.getWork());
                    System.out.println("今日概述:" + today.getSummary());
                    System.out.println("总指数:" + today.getAll());
                    break;
                case "tomorrow":
                    Tomorrow tomorrow = horoscopeCommon.getTomorrow();
                    System.out.println("日期:" + tomorrow.getDatetime());
                    System.out.println("星座名称:" + tomorrow.getName());
                    System.out.println("速配星座:" + tomorrow.getQFriend());
                    System.out.println("幸运色:" + tomorrow.getColor());
                    System.out.println("健康指数:" + tomorrow.getHealth());
                    System.out.println("爱情指数:" + tomorrow.getLove());
                    System.out.println("财运指数:" + tomorrow.getMoney());
                    System.out.println("幸运数字:" + tomorrow.getNumber());
                    System.out.println("财运指数:" + tomorrow.getMoney());
                    System.out.println("工作指数:" + tomorrow.getWork());
                    System.out.println("明日概述:" + tomorrow.getSummary());
                    System.out.println("总指数:" + tomorrow.getAll());
                    break;
                case "week":
                    Week week = horoscopeCommon.getWeek();
                    System.out.println("星座名称:" + week.getName());
                    System.out.println("日期:" + week.getDate());
                    System.out.println("健康:" + week.getHealth());
                    System.out.println("爱情:" + week.getLove());
                    System.out.println("财运:" + week.getMoney());
                    System.out.println("工作:" + week.getWork());
                    break;
                case "month":
                    Month month = horoscopeCommon.getMonth();
                    System.out.println("日期:" + month.getDate());
                    System.out.println("星座名称:" + month.getName());
                    System.out.println("月份:" + month.getMonth());
                    System.out.println(month.getHealth());
                    System.out.println(month.getLove());
                    System.out.println(month.getMoney());
                    System.out.println(month.getWork());
                    System.out.println(month.getAll());
                    break;
                case "year":
                    Year year = horoscopeCommon.getYear();
                    System.out.println("日期:" + year.getDate());
                    System.out.println("星座名称:" + year.getName());
                    System.out.println("年份:" + year.getYear());
                    System.out.println("概述:" + year.getMima().getInfo());
                    List<String> s;
                    for (String t : year.getMima().getText()
                    ) {
                        System.out.println("说明:" + t);
                    }
                    for (String c : year.getCareer()
                    ) {
                        System.out.println("事业运:" + c);
                    }
                    for (String l : year.getLove()
                    ) {
                        System.out.println("感情运:" + l);
                    }
                    for (String f : year.getFinance()
                    ) {
                        System.out.println("财运:" + f);
                    }
                    break;
                default:
                    System.out.println();
                    System.out.println("错误的运势类型，请重试！");
            }
        } else {
            System.out.println("错误的星座名称!!!");
        }

    }
}
